<?php

namespace App\Http\Resources;

use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

class Products extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param Request $request
     * @return array
     */
    public function toArray($request)
    {
        return [
            'id' => $this->id,
            'name' => $this->name,
            'cover' => Images::make($this->cover),
            'price' => $this->price,
            'tags' => Tags::collection($this->tags),
            'category' => Categories::make($this->category),
            'count_reviews' => $this->count_reviews,
            'count_sales' => $this->count_sales,
            'count_comments' => $this->count_comments,
            'is_collection' => (int)isCollectionProduct($this->id), // 是否收藏
        ];
    }
}
